package com.ldk.api;

/**
 * 结果类
 * @author xiangwl
 * @date 2015-06-25
 */
public class ResponseResult {
	
	public static ResponseObject success(String module, String method, Object result){
		ResponseObject response = new ResponseObject();
		
		response.setModule(module);
		response.setMethod(method);
		response.setSuccess(true);
		response.setResult(result);
		
		return response;
	}
	
	/**
	 * 成功结果
	 * @param response
	 * @param result
	 * @return
	 */
	public static ResponseObject success(ResponseObject response, Object result){
		
		response.setSuccess(true);
		response.setResult(result);
		
		return response;
	}
	
	/**
	 * 创建失败ResponseObject
	 * @param module
	 * @param method
	 * @param error
	 * @return
	 */
	public static ResponseObject exception(String module, String method, ResponseError error){
		ResponseObject response = new ResponseObject();
		
		response.setModule(module);
		response.setMethod(method);
		response.setSuccess(false);
		response.setError(error);
		
		return response;
	}
	
	/**
	 * 创建失败ResponseObject
	 * @param module
	 * @param method
	 * @param error
	 * @return
	 */
	public static ResponseObject exception(String module, String method, ErrorCode error){
		ResponseObject response = new ResponseObject();
		
		response.setModule(module);
		response.setMethod(method);
		response.setSuccess(false);
		response.setError(ResponseError.build(error));
		
		return response;
	}
	
	/**
	 * 创建失败ResponseObject
	 * @param requestObject
	 * @param error
	 * @return
	 */
	public static ResponseObject exception(RequestObject requestObject, ErrorCode error)
	{
			
		ResponseObject response = new ResponseObject();
		
		String module = requestObject == null ? "" : requestObject.getModule();
		String method = requestObject == null ? "" : requestObject.getMethod();
		
		response.setModule(module);
		response.setMethod(method);
		response.setSuccess(false);
		response.setError(ResponseError.build(error));
		
		return response;
	}
	
	/**
	 * 创建失败ResponseObject
	 * @param response
	 * @param error
	 * @return
	 */
	public static ResponseObject exception(ResponseObject response, ErrorCode error)
	{
		response.setSuccess(false);
		response.setError(ResponseError.build(error));
		
		return response;
	}
	
	
	/**
	 * 创建新的响应对象
	 * @param module
	 * @param method
	 * @return
	 */
	public static ResponseObject create(String module, String method){
		ResponseObject response = new ResponseObject();
		response.setModule(module);
		response.setMethod(method);
		
		return response;
	}
	
}
